#pragma once
#include <list>
#include <string>
using namespace std;
struct user_info;
typedef user_info USER_INFO;
typedef list<USER_INFO> USER_LIST;
struct message;
typedef message MESSAGE;
struct sockaddr_in;

class ChatCli {
public:
    ChatCli (const char *ipaddr = "127.0.0.1", int port = 5188);
    ~ChatCli ();
    bool start ();
    void run ();
private:
    int sock;
    string ipaddr;
    int port;
    sockaddr_in servaddr;


    // 当前用户名
    char username[16];

    // 聊天室成员列表
    USER_LIST client_list;

    // 当前用户数
    int count;

    void parseCmd(char* cmdline);
    bool sendMsgTo(char* name, char* msg);
    void logout ();
    void getUsrList();

    void do_someone_login(MESSAGE& msg);
    void do_someone_logout(MESSAGE& msg);
    void do_getlist();
    void do_chat(MESSAGE& msg);
};